package com.maybach.core.manager.impl;

import com.maybach.util.query.support.PageResult;
import com.maybach.common.model.CarFormalitiesDO;
import com.maybach.common.query.CarFormalitiesQuery;
import com.maybach.core.dal.mapper.ext.CarFormalitiesExtMapper;
import com.maybach.core.manager.CarFormalitiesManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * Manager for CarFormalities.
 */

@Component
public class CarFormalitiesManagerImpl implements CarFormalitiesManager{
    protected Logger log = LoggerFactory.getLogger(this.getClass());

    
    @Autowired
    protected CarFormalitiesExtMapper carFormalitiesExtMapper;
    /**
     * query count by query condition.
     */
    @Override
    public int countByQuery(CarFormalitiesQuery query){
        return carFormalitiesExtMapper.countByQuery(query);
    }

    /**
     * delete by query condition.
     */
    @Override
    public int deleteByQuery(CarFormalitiesQuery query){
        return carFormalitiesExtMapper.deleteByQuery(query);
    }

    /**
     * delete by primary key.
     */
    @Override
    public int deleteByPrimaryKey(CarFormalitiesDO record){
        return carFormalitiesExtMapper.deleteByPrimaryKey(record);
    }

    /**
     * insert selective.
     */
    @Override
    public long insertSelective(CarFormalitiesDO record){
        return carFormalitiesExtMapper.insertSelective(record);
    }

    /**
     * select by query condition.
     */
    @Override
    public List<CarFormalitiesDO> selectByQuery(CarFormalitiesQuery query){
        return carFormalitiesExtMapper.selectByQuery(query);
    }

    /**
     * select by query condition with page.
    */
    @Override
    public PageResult<CarFormalitiesDO> selectByQueryWithPage(CarFormalitiesQuery query) {
        PageResult<CarFormalitiesDO> result = new PageResult<CarFormalitiesDO>();
        result.setPageSize(query.getPageSize());
        result.setPageNo(query.getPageNo());
        result.setTotalCount(this.countByQuery(query));
        result.setResult(this.selectByQuery(query));
        return result;
    }

    /**
     * select by primary key.
     */
    @Override
    public CarFormalitiesDO selectByPrimaryKey(Long id){
        return carFormalitiesExtMapper.selectByPrimaryKey(id);
    }

    @Override
    public CarFormalitiesDO selectByOutOrderId(Long outOrderId) {
        CarFormalitiesQuery query = new CarFormalitiesQuery();
        CarFormalitiesQuery.Criteria criteria = query.createCriteria();
        criteria.andOutOrderIdEqualTo(outOrderId);
        query.clearPage();
        List<CarFormalitiesDO> carFormalitiesDOs = carFormalitiesExtMapper.selectByQuery(query);
        if (null != carFormalitiesDOs && !carFormalitiesDOs.isEmpty()) {
            return carFormalitiesDOs.get(0);
        } else {
            return null;
        }
    }

    /**
     * update by query condition selective.
     */
    @Override
    public int updateByQuerySelective( CarFormalitiesDO record,  CarFormalitiesQuery query){
        return carFormalitiesExtMapper.updateByQuerySelective(record,  query);
    }

    /**
     * update by query condition.
     */
    @Override
    public int updateByQuery( CarFormalitiesDO record,  CarFormalitiesQuery query){

        return carFormalitiesExtMapper.updateByQuery(record, query);
    }

    /**
     * update by primary key selective.
     */
    @Override
    public int updateByPrimaryKeySelective(CarFormalitiesDO record){
        return carFormalitiesExtMapper.updateByPrimaryKeySelective(record);
    }
}